const paginationBev = Behavior({

    data: {
        dataArray: [],
        total: null,
        loading: false,
        noneResult: false
    },

    methods: {
        getCurrentStart () {
            return this.data.dataArray.length
        },

        setMoreData (dataArray) {
            const tempArray = this.data.dataArray.concat(dataArray)
            this.setData({
                dataArray: tempArray
            })
        },

        setTotal (total) {
            this.data.total = total
            if (total === 0) {
                this.setData({
                    noneResult: true
                })
            }
        },

        hasMore () {
            if (this.data.dataArray.length >= this.data.total) {
                return false
            } else {
                return true
            }
        },

        initialize () {
            this.setData({
                dataArray: [],
                noneResult: false,
                loading: false
            })
            this.data.total = null
        },

        isLocked () {
            return !!this.data.loading
        },

        locked () {
            this.setData({
                loading: true
            })
        },

        unLocked () {
            this.setData({
                loading: false
            })
        }

    }

})

export { paginationBev }
